function $(selector){
	if(selector.charAt(0) == '#'){
		return document.getElementById(selector.substring(1));
	}else if(selector.charAt(0) == '.'){
		return document.getElementsByClassName(selector.substring(1));
	}else{
		return document.getElementsByTagName(selector);
	}
}
/*获取选择框的值*/
function getChecked(obj){
	for(var i in obj){
		if(obj[i].checked){
			return obj[i].value;
		}
	}
}
/*各类型的点击事件绑定*/
function typeClick(){
	switch(getChecked(document.getElementsByName('type'))){
		case 'text':
			$('.wrap3')[0].style.display = 'block';
			$('.wrap3')[0].innerHTML = '<legend>规则</legend><input type="radio" name="rules" value="user" checked="checked">用户名<input type="radio" name="rules" value="number">数字<input type="radio" name="rules" value="email">邮箱<input type="radio" name="rules" value="password">密码<input type="radio" name="rules" value="mobile">手机号';
			$('.wrap4')[0].style.display = 'block';
			$('.wrap4')[0].innerHTML = '<legend>字符限制</legend><label>字符范围<input type="text" id="min" value="4">--<input type="text" id="max" value="16"></label>';
			$('.wrap3')[0].onclick = function(){
				switch(getChecked(document.getElementsByName('rules'))){
				case 'number':
				case 'password':
					$('.wrap4')[0].style.display = 'block';
					break;
				case 'email':
				case 'mobile':
					$('.wrap4')[0].style.display = 'none';
					break;
				case 'user':
					$('.wrap4')[0].style.display = 'block';
					$('.wrap4')[0].innerHTML = '<legend>字符限制</legend><label>字符范围<input type="text" id="min" value="4">--<input type="text" id="max" value="16"></label>';
					break;
			} 
		}
			break;
		case 'select':
		case 'checkbox':
		case 'radio':
			$('.wrap3')[0].style.display = 'block';
			$('.wrap4')[0].style.display = 'none';
			$('.wrap3')[0].innerHTML = '<legend>选项</legend><input type="text" id="xuanxiang" placeholder="可以用空格，逗号，回车分割选项"><div id="item"></div>';
			$('#xuanxiang').onkeyup = function(){
				var regStr = new RegExp(/[\s\n\.\-。,，、]+/,'igm'),
						regStr1 = new RegExp(/(^[\s\n\.\-。,，、]*)|([\s\n\.\-。,，、]*$)/,'igm'),
						str = '';
				var temp = this.value.trim();
				if(temp){
					temp = temp.replace(regStr1,'').replace(regStr,'|').split('|');
				}
				if(temp != null){
					for(var i in temp){
						str += '<span>'+ temp[i] +'</span>';
					}
					$('#item').innerHTML = str;
				}
			};
			break;
		case 'textarea':
			$('.wrap3')[0].style.display = 'none';
			$('.wrap4')[0].style.display = 'block';
			break;
	}
}

$('.wrap1')[0].onclick = function(){
	typeClick();
};
/*初始化选择区域*/
typeClick();